﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title><%=title%></title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!-- Bootstrap 3.3.2 -->
    <link href="/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Font Awesome Icons -->
    <link href="/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <!-- Theme style -->
    <link href="/stylesheets/backstage/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="/javascripts/backstage/html5shiv.js"></script>
    <script src="/javascripts/backstage/respond.min.js"></script>
    <![endif]-->
    <script src="/javascripts/angular.min.js"></script>
</head>
<body class="login-page"ng-app="adminLogin" ng-controller="login">
<div class="login-box">
    <div class="login-logo">
        <a href="/"><b>Dora</b>CMS</a>
    </div><!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">系统管理员登录</p>
        <div class="alert alert-danger hide" role="alert" id="errorInfo"><i class="fa fa-exclamation-triangle"></i>&nbsp;用户名或密码不匹配</div>
        <form name="loginForm" ng-submit="processLogForm(loginForm.$valid)" novalidate>
            <div class="form-group has-feedback">
                <input type="text" class="form-control" ng-model="logFormData.userName" placeholder="请输入用户名"/>
                <span class="glyphicon glyphicon-user form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" class="form-control" ng-model="logFormData.password" placeholder="请输入密码"/>
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="form-group">
                <div class="col-md-6" style="margin-left: 0;padding-left: 0;">
                    <input type="text" class="form-control" name="vnum" ng-model="logFormData.vnum" placeholder="请输入验证码" required>
                </div>
                <span> <img id="vcode" src="/admin/vnum?<%=Date.parse(new Date())%>" /></span>
            </div>
            <div class="row">
                <div class="col-xs-8">
                    <div class="checkbox icheck hide">
                        <label>
                            <input type="checkbox"> Remember Me
                        </label>
                    </div>
                </div><!-- /.col -->
                <div class="col-xs-4">
                    <button type="submit" class="btn btn-primary btn-block btn-flat" ng-disabled="loginForm.$invalid">登录</button>
                </div><!-- /.col -->
            </div>
        </form>
    </div><!-- /.login-box-body -->
</div><!-- /.login-box -->

<!-- jQuery 2.1.3 -->
<script src="/javascripts/jQuery-2.1.3.min.js" type="text/javascript"></script>
<!-- Bootstrap 3.3.2 JS -->
<script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
<script>

    angular.module("adminLogin",[])
            .controller("login",function($scope,$http){
                $scope.processLogForm = function(isValid){
                    if(isValid){
                        $http({
                            method  : 'POST',
                            url     : "/admin/doLogin",
                            data    : $.param($scope.logFormData),  // pass in data as strings
                            headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
                        })
                        .success(function(data) {
                            if(data === "success"){
                                window.location = "/admin/manage"
                            }else{
                                $("#errorInfo").removeClass('hide').text(data);
                                var newParams = Math.round(Math.random() * 100) + '<%=Date.parse(new Date())%>';
                                $('#vcode').attr('src','/admin/vnum?'+newParams);
                            }
                        });
                    }
                    else{
                        alert("error");
                    }
                }
            })
</script>
</body>
</html>